//
//  ZLHomeViewController.swift
//  Swift-weibo
//
//  Created by 朱万龙 on 2016/12/9.
//  Copyright © 2016年 zwl. All rights reserved.
//

import UIKit

private let cellID = "cellID"

class ZLHomeViewController: ZLBaseViewController {

    fileprivate lazy var statusList = [String]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        tableView?.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: cellID)
    }
    //重写父类方法
    override func loadData() {
        //开始加载数据
        print("开始加载数据")
        
        ZLNetWorkManger.share.statusList { (result, isSuccess) in
            print(result)
        }
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1, execute: {
            for i in 0..<15 {
                //利用标记区分上下拉刷新
            if self.isPullup{
                //追加到数组最后
            self.statusList.append("上拉\(i)")
                print("上拉刷新\(i)")
                print(self.isPullup)
            }else{
                //插入到数组顶端
                self.statusList.insert(i.description, at: 0)
                print("下拉刷新\(i)")
                print(self.isPullup)
            }
                //结束
                self.refreshControl?.endRefreshing()
                //刷新表格
                self.tableView?.reloadData()
            }
            ///跳出循环 恢复标记
            //恢复标记
            self.isPullup = false
        })
     
    }

}
// MARK: - 重写父类方法，设置本类信息
extension ZLHomeViewController{
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusList.count
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: cellID, for: indexPath)
        
        cell.textLabel?.text = statusList[indexPath.row]
        
        return cell
    }
    
}
extension ZLHomeViewController{

    override func setUpTableView() {
        super.setUpTableView()
        
        navItem.leftBarButtonItem = UIBarButtonItem(title: "好友", fontSize: 16, target: self, action: #selector(leftButtonItemCilck))
        
    }
    func leftButtonItemCilck() {
        let vc = ZLDomeViewController()
        navigationController?.pushViewController(vc, animated: true)
    }
}
